dnl Process this file with autoconf to produce a configure script.

AC_PREREQ(2.52)

AC_INIT(stardict, 2.4.10, http://stardict-4.sourceforge.net)
AC_CONFIG_SRCDIR(src/stardict.cpp)
AM_INIT_AUTOMAKE([tar-ustar dist-xz])
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

AM_MAINTAINER_MODE
AM_CONFIG_HEADER(config.h)
AM_DISABLE_STATIC

AC_PATH_PROG(GCONFTOOL, gconftool-2)
AC_PROG_INTLTOOL([0.22])
PKG_PROG_PKG_CONFIG

AC_CONFIG_MACRO_DIRS([m4])
LT_INIT

AC_ISC_POSIX
AC_PROG_CC
AC_PROG_CXX
AC_LANG([C++])
AC_PROG_INSTALL
AC_PROG_MAKE_SET


AC_FUNC_MMAP


dnl ================================================================
dnl Gettext stuff.
dnl ================================================================
GETTEXT_PACKAGE=stardict
AC_SUBST(GETTEXT_PACKAGE)
AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package])
ALL_LINGUAS="cs de el fr hu hr ku mk nl pt_BR ru sk tt uk vi zh_CN zh_TW"
AM_GLIB_GNU_GETTEXT

AC_ARG_ENABLE(gnome-support, AC_HELP_STRING([--disable-gnome-support], [Disable gnome support]))
AC_ARG_ENABLE(gpe-support, AC_HELP_STRING([--enable-gpe-support], [Enable gpe support]))
AM_CONDITIONAL(GNOME_SUPPORT, test "x${enable_gpe_support}" != "xyes" && test "x${enable_gnome_support}" != "xno")
AM_CONDITIONAL(GPE_SUPPORT, test "x${enable_gpe_support}" = "xyes")

if test "x${enable_gpe_support}" = "xyes" ; then
  DEP_MODULES="gtk+-2.0 >= 2.4 glib-2.0 >= 2.2 gdk-2.0 gdk-pixbuf-2.0 atk gobject-2.0 gio-2.0 libgpewidget >= 0.109"
elif test "x${enable_gnome_support}" = "xno" ; then
  DEP_MODULES="gtk+-2.0 >= 2.6 glib-2.0 gdk-2.0 gdk-pixbuf-2.0 atk gobject-2.0 gio-2.0"
else
  DEP_MODULES="libgnomeui-2.0 >= 2.2.0 glib-2.0 gdk-2.0 gdk-pixbuf-2.0 atk gobject-2.0 gio-2.0"
fi

dnl
dnl Start of pkg-config checks
dnl
PKG_CHECK_MODULES(STARDICT, $DEP_MODULES)

if test "x${enable_gpe_support}" = "xyes" ; then
        echo "Enable gpe suppport";
	AC_DEFINE([CONFIG_GPE],[], [Compile with gpe support])
	AM_CONDITIONAL(SCHEMAS_INSTALL, test "x${enable_gpe_support}" != "xyes")
	AM_CONDITIONAL(GCONF_SCHEMAS_INSTALL, test "x${enable_gpe_support}" != "xyes")
elif test "x${enable_gnome_support}" = "xno" ; then
	echo "Disable gnome support";
	AC_DEFINE([CONFIG_GTK],[], [Compile without gnome support])
	AM_CONDITIONAL(SCHEMAS_INSTALL, test "x${enable_gnome_support}" != "xno")
	AM_CONDITIONAL(GCONF_SCHEMAS_INSTALL, test "x${enable_gnome_support}" != "xno")
else
	echo "Enable gnome suppport";
	AC_DEFINE([CONFIG_GNOME],[], [Compile with gnome support])

dnl *********************************************
dnl for anything which calls gconftool-2 correctly
dnl *********************************************

	AC_PATH_PROG(GCONFTOOL, gconftool-2, no)
	if test x"$GCONFTOOL" = xno; then
        	AC_MSG_ERROR([gconftool-2 executable not found in your path - should be installed with GConf])
	fi
	AM_GCONF_SOURCE_2

	AM_CONDITIONAL(SCHEMAS_INSTALL, test x$schemas_install = xtrue)
dnl ==========================================================================
dnl stuff for the CORBA interface

	ORBIT_IDL="`$PKG_CONFIG --variable=orbit_idl ORBit-2.0`"
	AC_SUBST(ORBIT_IDL)

	LIBBONOBO_IDL="`$PKG_CONFIG --variable=idldir libbonobo-2.0`"
	AC_SUBST(LIBBONOBO_IDL)

	BONOBO_ACTIVATION_IDL="`$PKG_CONFIG --variable=idldir bonobo-activation-2.0`"
	AC_SUBST(BONOBO_ACTIVATION_IDL)

dnl
dnl Check popt
dnl

	AC_CHECK_LIB(popt, poptStrippedArgv,, AC_MSG_ERROR([popt 1.5 or newer is required to build
stardict. You can download the latest version from ftp://people.redhat.com/sopwith/popt/]))

fi


STARDICT_CFLAGS="-Wall $STARDICT_CFLAGS"


#dnl
#dnl Start of zlib checks
#dnl
AC_CHECK_LIB(z,zlibVersion,STARDICT_LIBS="$STARDICT_LIBS -lz",[AC_MSG_ERROR([zlib not found, or gcc g++ not installed])])
# For the first AC_CHECK_LIB, if failed, it may because of compiler didn't installed. So add this warning for the first AC_CHECK_LIB macro.

dnl
dnl Start of bz2 checks
dnl
AC_CHECK_LIB(bz2,BZ2_bzlibVersion,STARDICT_LIBS="$STARDICT_LIBS -lbz2",[AC_MSG_ERROR([libbz2 not found])])

dnl
dnl Start of lz checks
dnl
AC_CHECK_LIB(lz,LZ_version,STARDICT_LIBS="$STARDICT_LIBS -llz",[AC_MSG_ERROR([liblz not found])])

dnl
dnl Start of xz lzma checks
dnl
dnl ls -l /usr/bin/lzma
dnl /usr/bin/lzma -> /etc/alternatives/lzma
dnl
dnl ls -l /etc/alternatives/lzma
dnl /etc/alternatives/lzma -> /usr/bin/xz
dnl
AC_CHECK_LIB(lzma,lzma_version_string,STARDICT_LIBS="$STARDICT_LIBS -llzma",[AC_MSG_ERROR([liblzma not found])])

dnl
dnl Start of zstd checks
dnl
AC_CHECK_LIB(zstd,ZSTD_versionString,STARDICT_LIBS="$STARDICT_LIBS -lzstd",[AC_MSG_ERROR([libzstd not found])])

dnl
dnl Start of lzo2 checks
dnl
AC_CHECK_LIB(lzo2,lzo_version_string,STARDICT_LIBS="$STARDICT_LIBS -llzo2",[AC_MSG_ERROR([liblzo2 not found])])


dnl ==========================================================================

# Checks for header files. need by Solaris.
AC_PATH_XTRA
if test -n "$X_CFLAGS"; then
CPPFLAGS="$CPPFLAGS $X_CFLAGS"
fi
if test -n "$X_LIBS"; then
LDFLAGS="$LDFLAGS $X_LIBS"
fi
if test -n "$X_PRE_LIBS"; then
LDFLAGS="$LDFLAGS $X_PRE_LIBS"
fi
if test -n "$X_EXTRA_LIBS"; then
LDFLAGS="$LDFLAGS $X_EXTRA_LIBS"
fi

# Checks for libraries.
AC_CHECK_LIB([X11], [main], , [AC_MSG_ERROR([X11 lib not found])])

AC_SUBST(STARDICT_LIBS)
AC_SUBST(STARDICT_CFLAGS)

dnl ==========================================================================

AC_OUTPUT([
Makefile
spec/Makefile
spec/stardict.spec
spec/stardict-withoutgnome.spec
data/Makefile
doc/Makefile
debian-upstream/Makefile
debian-upstream/source/Makefile
debian-upstream/upstream/Makefile
po/Makefile.in
src/Makefile
src/lib/Makefile
src/parsedata/Makefile
src/parsedata/parsedata_powerword/Makefile
src/parsedata/parsedata_wiki/Makefile
src/parsedata/parsedata_xdxf/Makefile
src/parsedata/parsedata_html/Makefile
src/parsedata/parsedata_wordnet/Makefile
src/pixmaps/Makefile
src/sounds/Makefile
src/win32/Makefile
src/win32/acrobat/Makefile
src/win32/acrobat/sources/Makefile
src/win32/acrobat/win32/Makefile
src/win32/nsis/Makefile
tests/Makefile
pixmaps/Makefile
icons/Makefile
icons/16x16/Makefile
icons/24x24/Makefile
icons/32x32/Makefile
icons/48x48/Makefile
icons/64x64/Makefile
icons/96x96/Makefile
icons/128x128/Makefile
icons/scalable/Makefile
help/Makefile
help/C/Makefile
help/zh_CN/Makefile
help/zh_TW/Makefile
help/ru/Makefile
help/mk/Makefile
help/nl/Makefile
help/uk/Makefile
])


echo "

Type \"make\" to compile StarDict.

"
